package aad.storyboard;



import java.io.FileNotFoundException;

import org.xml.sax.InputSource;

import utils.MyXMLHandler;
import aad.storyboard.controller.ControllerManager;
import aad.storyboard.controller.GUIComposer;
import aad.storyboard.model.ImageFactory;
import aad.storyboard.controller.StoryTimer;
import aad.storyboard.model.AnimationProvider;
import aad.storyboard.model.Chapter;

import aad.storyboard.model.Image;
import aad.storyboard.model.ImageProvider;
import aad.storyboard.model.InfoAnimation;
import aad.storyboard.model.Layer;
import aad.storyboard.model.MoveAnimation;
import aad.storyboard.model.RotateAnimation;
import aad.storyboard.model.ScaleAnimation;
import aad.storyboard.model.Scene;
import aad.storyboard.model.Script;
import aad.storyboard.model.Story;
import aad.storyboard.view.ControlView;




import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;
import android.widget.MediaController;
import android.widget.SeekBar;
import android.widget.ViewFlipper;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;

public class Test extends Activity{



private StoryTimer timer;

private MediaPlayer mediaplayer;
private Context context;

private ViewFlipper flipper;



SeekBar volControl=null;

AudioManager audioManager;
int maxVolume;
int curVolume;


private ImageButton media=null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
	    this.setContentView(R.layout.mainwithoutwebview);

       context=this;
       
       Story s = Story.getInstance();
       ControllerManager.getInstance().setupControllers(s,this,R.layout.mainwithoutwebview);
       //timer = StoryTimer.getInstance();
	   //System.out.println("Seekbar"+volControl.toString());
	
  /*ScriptParser p=new ScriptParser();
  InputStream input=getResources().openRawResource(R.raw.subtitles);
  ArrayList <Script> scripts=p.initialiseSubtitleTimes(input, p);
  sc1.setScripts(scripts);*/
  
  
	
	   InputSource is = new InputSource(getResources().openRawResource(R.raw.story));
	   MyXMLHandler handler=new MyXMLHandler();
	   handler.getXMLdata(is);
	   s.setAudioFile(R.raw.fulljabber);
	  Chapter c=Story.getChapters().get(0);
	  s.setCurrentChapter(c);
	  c.setStartTime(0);
	  c.setEndTime(1000000);
	  c.setCurrentScene(c.getScenes().get(0));
	  
	 
	  Layer l1 = new Layer();
	  Layer l2 = new Layer();

	  Image img1,img2,bgimg;
	  ImageProvider provider = ImageProvider.getInstance(this.getResources());
	try {
	      img1 = provider.getImage(R.raw.cheshire_cat);
	      
	      img1.setPosX(-100);
	      img1.setPosY(-100);
	      
	      MoveAnimation move=new MoveAnimation(0, 100, 100, 10);
	      move.addImage(img1);
	      AnimationProvider acontroller = AnimationProvider.getInstance();
	      
	      acontroller.addAnimation(img1, move, AnimationProvider.EVENT_NONE);
	      img2 = provider.getImage(R.raw.beamish_boy);
	      img2.setPosX(-250);
	      img2.setPosY(-100);
	      ScaleAnimation scale = new ScaleAnimation(1.5f,1.5f,10);
	      scale.addImage(img2);
	      acontroller.addAnimation(scale, AnimationProvider.EVENT_TOUCH);
	      l2.addImage(img1);
	      l2.addImage(img2);
	      
	     

	} catch (Exception e) {
	       e.printStackTrace();
	}

	  /*Script scr = new Script("This is a sample subtitle to show that our subtitles are very functional, nitid and readable =)!");
	  scr.setStartTime(1000);
	  scr.setPosX(100);
	  scr.setPosY(200);
	  l2.addScript(scr);*/
	  c.getScenes().get(0).addLayer(0, l1);
	  c.getScenes().get(0).addLayer(1, l2);
	  c.getScenes().get(1).addLayer(0, l1);
	  c.getScenes().get(1).addLayer(1, l2);
	  c.getScenes().get(2).addLayer(0, l1);
	  c.getScenes().get(2).addLayer(1, l2);
	  c.getScenes().get(3).addLayer(0, l1);
	  c.getScenes().get(3).addLayer(1, l2);
	  c.getScenes().get(4).addLayer(0, l1);
	  c.getScenes().get(4).addLayer(1, l2);
	  c.getScenes().get(5).addLayer(0, l1);
	  c.getScenes().get(5).addLayer(1, l2);
	  c.getScenes().get(6).addLayer(0, l1);
	  c.getScenes().get(6).addLayer(1, l2);
	  c.getScenes().get(7).addLayer(0, l1);
	  c.getScenes().get(7).addLayer(1, l2);
	 

	 ControllerManager.getInstance().startStory();
	  //g.start();
	  
	 


    //----------------------------------------------
	
      
}

@Override
public void onDestroy() {
       super.onDestroy();
       //AudioPlayer.setState(0);
       //AudioPlayer.stopPlayer();
       mediaplayer.release();
}







}